package com.hk.jmm.model;

import com.hk.jmm.api.AppApiService;
import com.skyz.base.manager.RetrofitManager;
import com.skyz.base.mvp.IModel;
import com.skyz.base.util.RxUtils;
import com.skyz.wrap.http.CommonAppHttpRequestCallback;

import java.util.HashMap;
import java.util.Map;

public class LoginByPasswordModel implements IModel {

    public void showPhoneLogin(String accout, String pass, ModelCallBack<String> callBack) {
        Map<String, String> map = new HashMap<>();
        map.put("username", accout);
        map.put("password", pass);
        RetrofitManager.getInstance().getService(AppApiService.class)
                .loginByPassword(map)
                .compose(RxUtils.io4main())
                .subscribe(new CommonAppHttpRequestCallback<String>(true) {
                    @Override
                    protected void onCommonAppHttpRequestSuccess(String token) {
                        if (callBack != null) {
                            callBack.onSuccess(token);
                        }
                    }

                    @Override
                    protected void onCommonAppHttpRequestNetWorkUsable() {
                        if (callBack != null) {
                            callBack.newWorkEable();
                        }
                    }
                });
    }

    public void showPhoneLoginByQrcode(String accout, String pass, ModelCallBack<String> callBack) {
        Map<String, String> map = new HashMap<>();
        map.put("username", accout);
        map.put("password", pass);
        map.put("loginType", "1");
        RetrofitManager.getInstance().getService(AppApiService.class)
                .loginByPassword(map)
                .compose(RxUtils.io4main())
                .subscribe(new CommonAppHttpRequestCallback<String>(true) {
                    @Override
                    protected void onCommonAppHttpRequestSuccess(String token) {
                        if (callBack != null) {
                            callBack.onSuccess(token);
                        }
                    }

                    @Override
                    protected void onCommonAppHttpRequestNetWorkUsable() {
                        if (callBack != null) {
                            callBack.newWorkEable();
                        }
                    }
                });
    }


}
